package com.cy.aircompressor.main.home.systemsetting.provider;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;

import com.cy.aircompressor.databinding.ItemPowerManagerLayoutBinding;
import com.cy.aircompressor.entity.power.PowerStation;
import com.cy.aircompressor.main.home.systemsetting.detail.PowerStationAddOrUpdateDialog;
import com.cy.aircompressor.main.home.systemsetting.detail.UserInfoAddOrUpdateDialog;
import com.drug.lib.view.recycptr.ItemViewBinder;
import com.jakewharton.rxbinding2.view.RxView;
import com.net.model.base.BaseBindViewHolder;

import java.util.concurrent.TimeUnit;

public class PowerManagerProvider extends ItemViewBinder<PowerStation, PowerManagerProvider.ViewHolder> {
    Context mContext;
    FragmentManager fragmentManager;

    public PowerManagerProvider(Context mContext, FragmentManager fragmentManager) {
        this.mContext = mContext;
        this.fragmentManager = fragmentManager;
    }

    @NonNull
    @Override
    protected PowerManagerProvider.ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        return new ViewHolder(ItemPowerManagerLayoutBinding.inflate(inflater, parent, false));

    }

    @Override
    protected void onBindViewHolder(@NonNull PowerManagerProvider.ViewHolder holder, @NonNull PowerStation entity) {
        holder.mBinding.serial.setText(String.valueOf(holder.getAdapterPosition()));
        holder.mBinding.powerStationName.setText(entity.getName());
        holder.mBinding.remake.setText(entity.getRemark());
        holder.itemView.setBackgroundColor(Color.parseColor(holder.getAdapterPosition() % 2 == 0 ? "#1B485E" : "#0E3A50"));
        RxView.clicks(holder.mBinding.editBtn)
                .throttleFirst(500, TimeUnit.MILLISECONDS)
                .subscribe(o -> {
                    PowerStationAddOrUpdateDialog.showDialogFragment(fragmentManager, "power_station", true, entity);
                });
        RxView.clicks(holder.mBinding.detail)
                .throttleFirst(500, TimeUnit.MILLISECONDS)
                .subscribe(o -> {
                    PowerStationAddOrUpdateDialog.showDialogFragment(fragmentManager, "power_station", false, entity);
                });
    }


    public class ViewHolder extends BaseBindViewHolder<ItemPowerManagerLayoutBinding> {

        protected ViewHolder(ItemPowerManagerLayoutBinding itemView) {
            super(itemView);
        }
    }


}
